
package com.jf.cloud.user.feign;

import com.jf.cloud.api.user.feign.UserLevelAndScoreOrderFeignClient;
import com.jf.cloud.common.order.vo.ShopCartOrderMergerVO;
import com.jf.cloud.common.product.constant.PreSaleType;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.user.manager.UserLevelOrderManager;
import com.jf.cloud.user.manager.UserScoreOrderManager;
import com.jf.cloud.user.service.UserScoreLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Hidden;

import java.util.List;
import java.util.Objects;

/**
 * 用户等级积分订单计算feign连接
 * @author zz
 * @date 2021/05/10
 */
@RestController
@Hidden
public class UserLevelAndScoreOrderFeignController implements UserLevelAndScoreOrderFeignClient {


    @Autowired
    private UserScoreOrderManager userScoreOrderManager;

    @Autowired
    private UserLevelOrderManager userLevelOrderManager;

    @Autowired
    private UserScoreLogService userScoreLogService;


    @Override
    public ServerResponseEntity<ShopCartOrderMergerVO> calculateLevelAndScoreDiscount(ShopCartOrderMergerVO shopCartOrderMerger) {
        // 订单预售不能参与积分等级优惠
//        if(Objects.equals(shopCartOrderMerger.getPreSaleType(), PreSaleType.DEPOSIT.value())) {
//            return ServerResponseEntity.success(shopCartOrderMerger);
//        }
        userLevelOrderManager.calculateLevelDiscount(shopCartOrderMerger);
        userScoreOrderManager.calculateScoreDiscount(shopCartOrderMerger);
        return ServerResponseEntity.success(shopCartOrderMerger);
    }

    @Override
    public ServerResponseEntity<Long> getScoreCount(List<Long> refundIds) {
        return ServerResponseEntity.success(userScoreLogService.getScoreCountByRefundIds(refundIds));
    }

    @Override
    public ServerResponseEntity<Boolean> getHaveFreeFeeRight(Long userId, Long shopId) {
        Boolean haveFreeFeeRight = userLevelOrderManager.getHaveFreeFeeRight(userId, shopId);
        return ServerResponseEntity.success(haveFreeFeeRight);
    }
}
